package com.sam.widget.headerBar;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.sam.jifenbao.R;

public class BaseTitleBar extends BaseHeaderView {
    private String titleText;
    private TextView titleView;
    private int titleTextColor;
    private float titleTextSize;

    public BaseTitleBar(Context context) {
        super(context);
    }

    public BaseTitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BaseTitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void getAttrs(AttributeSet attrs) {
        super.getAttrs(attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.BaseTitleBar);
        titleText = ta.getString(R.styleable.BaseTitleBar_titleText);
        titleTextColor = ta.getColor(R.styleable.BaseTitleBar_titleTextColour, Color.WHITE);
        titleTextSize = ta.getDimension(R.styleable.BaseTitleBar_titleTextSize,40);
        ta.recycle();
    }

    @Override
    protected void findView() {
        super.findView();
        titleView = new TextView(context);
    }

    @TargetApi(Build.VERSION_CODES.M)
    @Override
    protected void initView() {
        super.initView();
//        titleView.setTextAppearance(R.style.header_title_style);
        titleView.setText(titleText);
        titleView.setTextColor(titleTextColor);
        titleView.setTextSize(titleTextSize);
    }

    public void setTitleText(String str){
        titleView.setText(str == null ? "" : str);
    }

    @Override
    public View getLeftView() {
        return null;
    }

    @Override
    public View getCenterView() {
        return titleView;
    }

    @Override
    public View getRightView() {
        return null;
    }
}
